(function (exports) {

    var $ = null;
    var MIN_ROTAT_TIMES = 3;
    var MAX_ROTAT_TIMES = 6;

    var LotteryLayer = cc.Layer.extend({

        onEnter: function () {
            cc.Layer.prototype.onEnter.call(this);
        },
        onCCSLoadFinish: function () {
            var that = this;
        },
        onExit: function () {
            cc.Layer.prototype.onExit.call(this);
        },
        ctor: function () {
            this._super();

            var that = this;

            loadCCSTo(res.LotteryLayer_json, this, "Layer");
            $ = create$(this.getChildByName("Layer"));
            shipei($);

            TouchUtils.setOnclickListener($('top.close'), function (node) {
                that.removeFromParent();
            });
            var zhuanArr = [];
            //逆时针 12点是1 6点5
            TouchUtils.setOnclickListener($('root.turnTable.lucky_btn'), function (node) {
                $('root.turnTable.lucky_arrow').runAction(that.createRotatAction(5));
            });
        },
        randRotatTimes: function () {
            return Math.floor(Math.random() * (MAX_ROTAT_TIMES - MIN_ROTAT_TIMES) + MIN_ROTAT_TIMES);
        },
        createRotatAction: function (dist) {
            var rotatTimes = this.randRotatTimes();
            var roundAction = cc.rotateBy(1.5, 360);
            var restAction = cc.rotateTo(0, 0);
            var roundTimesAction = cc.repeat(roundAction, rotatTimes);
            var distRadian = this.clacRadian(dist);
            var distRadianAction = cc.rotateBy(2, distRadian);
            var callback = cc.callFunc(function () {
            }.bind(this));
            return cc.sequence(restAction, roundTimesAction, distRadianAction, callback).easing(cc.easeInOut(3));
        },
        clacRadian: function (dist) {
            return 360 - Math.floor(360 * (dist - 1) / 8);
        }
    });
    exports.LotteryLayer = LotteryLayer;
})(window);
